package main

import (
	"BlendChar/blend"
	"BlendChar/save"
	"BlendChar/sdf"
	"fmt"
	"os"
	"sync"
)

var wg sync.WaitGroup

func main() {
	url := "./sample/%d.png"
	//样本数
	n := 2
	//获取长和宽
	sdfs := make([][][]float64, n)
	length, width, _ := sdf.GetLengthAndWidth(fmt.Sprintf(url, 0))
	var err error
	//计算有向距离场
	for i := 0; i <= n-1; i++ {
		wg.Add(1)
		go func(i int) {
			defer wg.Done()
			photoSDF, err := sdf.GetSDF(fmt.Sprintf(url, i))
			if err != nil {
				fmt.Println(err)
				os.Exit(1)
			}
			sdfs[i] = photoSDF
		}(i)
	}
	//同步
	wg.Wait()
	//混合
	res := blend.BlendChar(sdfs[0], sdfs[1], length, width)
	//保存
	err = save.SaveInPNG(length, width, res, "./demo.png")
	if err != nil {
		fmt.Println(err)
	}
}
